import {requestInfo} from '@/api/public.js'
import {http} from '@/api/service.js'
import {BASE_URL} from "../../service";
export class attachmentService {
    //上传附件
    static saveFile(formData){
        return requestInfo({
            method: 'post',
            url: "/erp/system/Attachment/saveAttachment",
            data: formData,
            // headers: {
            //   'Content-Type': 'multipart/form-data'
            // },
        })
    }
    //返回已上传的附件
    static findFile(id, name){
        return requestInfo({
            method: 'get',
            url: "/erp/system/Attachment/findAllUploadedFilesByIdAndName",
            params: {
                id: id,
                name: name
            },
            auth: false
        })
    }
    //下载附件
    static down(attachmentId){
        return requestInfo({
            method: 'get',
            url: "/erp/system/Attachment/download",
            params: {
                isOnline: false,
                attachmentId:attachmentId,
            },
            responseType: 'blob',
        })
    }
    //删除附件
    static deleteFile(attachmentId){
        return requestInfo({
            method: 'post',
            url: "/erp/system/Attachment/deleteAttachmentOfAttId",
            params: {attachmentId: attachmentId}
        })
    }
    static uploadFiles(files,associateFormId,associateFormName){
        files.forEach(f => {
            uni.uploadFile({
                url: BASE_URL + '/erp/system/Attachment/appSaveAttachment', //仅为示例，非真实的接口地址
                header: {
                    "Authorization": uni.getStorageSync('token'),
                    'Content-Type': 'multipart/form-data'
                },
                filePath: f.path,
                name: 'file',
                formData: {
                    "associateFormId": associateFormId,
                    "associateFormName": associateFormName
                },
                success: (uploadFileRes) => {
                    console.log(uploadFileRes.data);
                },
                fail: (e => {
                    console.log(e)
                })
            });
        })

    }

}